package com.atguigu.yygh.common.exception;

import com.atguigu.yygh.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @FileName: GlobalExceptionHandler
 * @Author Steven
 * @Date: 2021/3/14
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result error(){
        return Result.fail();
    }

    /**
     * @param e 自定义异常类
     * @return 返回状态码及异常信息
     */
    @ExceptionHandler(YyghException.class)
    public Result error(YyghException e){
        return Result.build(e.getCode(),e.getMessage());
    }
}
